let _fontName = ref "Monospace 10"
let rBg = ref 11822
let gBg = ref 13364
let bBg = ref 13878
let rFg = ref 65535
let gFg = ref 65535
let bFg = ref 65535
let openedFiles = ref []

let readSettings _ = if(Sys.file_exists "settings") then
               begin 
                   let channelColor = open_in "settings" in 
                       if(input_line channelColor = "Bg") then
                        begin 
                            rBg := int_of_string (input_line channelColor);
                            gBg := int_of_string (input_line channelColor);
                            bBg := int_of_string (input_line channelColor)
                        end; 
                       if(input_line channelColor = "Fg") then
                        begin 
                            rFg := int_of_string (input_line channelColor);
                            gFg := int_of_string (input_line channelColor);
                            bFg := int_of_string (input_line channelColor)
                        end; 
                       if(input_line channelColor = "Font") then
                           _fontName := input_line channelColor;
 		       if(input_line channelColor = "Files") then
                        begin 
			    openedFiles := [];
			    let files = ref (input_line channelColor) in
                            while !files <> "end" do
				begin 					
					openedFiles := !openedFiles @ [!files];
					files := input_line channelColor;
				end
			    done;
                        end; 
                       close_in channelColor;
               end

let getOpenFilesPath _ = 
    let paths = ref [] in
    List.iter 
	(fun x -> try 
		 let path = Hashtbl.find !Function._hashTblPath x in
                  paths := !paths@[path]
		 with _ -> ()
	) !Function._listText;
    !paths

let writeSettings _ = 
	let channelColor = open_out "settings" in
            output_string channelColor "Bg\n";
	    output_string channelColor ((string_of_int !rBg)^"\n");
	    output_string channelColor ((string_of_int !gBg)^"\n");
	    output_string channelColor ((string_of_int !bBg)^"\n");
	    output_string channelColor "Fg\n";
	    output_string channelColor ((string_of_int !rFg)^"\n");
	    output_string channelColor ((string_of_int !gFg)^"\n");
	    output_string channelColor ((string_of_int !bFg)^"\n");
 	    output_string channelColor "Font\n";
	    output_string channelColor (!_fontName^"\n");
	    output_string channelColor "Files\n";
	    List.iter (fun x -> output_string channelColor (x^"\n")) (getOpenFilesPath ());
	    output_string channelColor "end";
            close_out channelColor
      
let getBgColor _ = readSettings ();
		(!rBg,!gBg,!bBg)

let getFgColor _ = readSettings ();
		(!rFg,!gFg,!bFg)

let getFont _ = readSettings ();
		!_fontName
               
